package org.csu.demo.nettydemo.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.csu.demo.nettydemo.common.CommonResponse;
import org.csu.demo.nettydemo.domain.User;
import org.csu.demo.nettydemo.persistence.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public CommonResponse<User> login(String username, String password) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("nickname", username);
        queryWrapper.eq("password", password);

        User user = userMapper.selectOne(queryWrapper);
        if (user == null) {
            return CommonResponse.createForError("用户名或密码错误");
        }else {
            user.setPassword(null);
            return CommonResponse.createForSuccessMessage("登录成功",user);
        }
    }
}
